//
//  UITableView+ScrollBottom.m
//  ThunderChat
//
//  Created by Kelly xu on 2018/11/27.
//  Copyright © 2018 Simubang. All rights reserved.
//

#import "UITableView+ScrollBottom.h"

@implementation UITableView (ScrollBottom)
- (CGFloat)verticalOffsetOnBottom {
    CGFloat viewHeight = self.bounds.size.height;
    CGFloat contentHeight = self.contentSize.height;
    CGFloat topInset = self.contentInset.top;
    CGFloat bottomInset = self.contentInset.bottom;
    CGFloat bottomOffset = floorf(contentHeight - bottomInset - topInset - viewHeight);
    return MAX(bottomOffset, 0);
}

- (void)scrollToBottom:(BOOL)animated {
    if (self.contentSize.height + self.contentInset.top > self.frame.size.height)
    {
        CGPoint offset = CGPointMake(0, self.contentSize.height - self.frame.size.height+50);
        [self setContentOffset:offset animated:animated];
    }
}
@end
